package test

import (
	"fmt"
	"io/ioutil"
	"net/http"
	"sync"
	"testing"
)

var wt sync.WaitGroup

func TestDeleteRepo(t *testing.T) {
/*	repo, err := models.GetIssueTplGroupByRepo()
	if err != nil {
		t.Error(err)
	} else {*/
	repo := []string{"javamail","libssh","libraw","flex","glibc","gstreamer","binutils","cairo","bouncycastle"}
		for _, v := range repo {
			go func(rep string) {
				wt.Add(1)
				defer wt.Done()
				_ = deleteRepo("zhangjianjun_code", rep, "bee5383db9aa3f19663b8aab82b76289")

			}(v)
		}
	//}
	wt.Wait()
}

func deleteRepo(owner, repo, token string) error {
	url := fmt.Sprintf("https://gitee.com/api/v5/repos/%s/%s?access_token=%s", owner, repo, token)
	request, err := http.NewRequest(http.MethodDelete, url, nil)
	if err != nil {
		return err
	}

	rsp, err := http.DefaultClient.Do(request)
	if err != nil {
		return err
	}
	defer rsp.Body.Close()

	body, _ := ioutil.ReadAll(rsp.Body)
	fmt.Println(string(body))

	return nil
}
